package com.wwm.findit;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.ArrayList;

/**
 * @author alessandro.balocco
 */
public class SimpleAdapter extends BaseAdapter
{

	private LayoutInflater layoutInflater;
	private ArrayList<Item> itemArray;

	public SimpleAdapter(Context context)
	{
		layoutInflater = LayoutInflater.from(context);
		this.itemArray = null;
	}

	@Override
	public int getCount()
	{
		if (this.itemArray != null)
		{
			return this.itemArray.size();
		}
		return 3;
	}

	@Override
	public Object getItem(int position)
	{
		return itemArray.get(position);
	}

	@Override
	public long getItemId(int position)
	{
		return position;
	}

	public void setData(ArrayList<Item> itemArray)
	{
		this.itemArray = itemArray;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent)
	{
		ViewHolder viewHolder;
		View view;

		view = layoutInflater.inflate(R.layout.get_info, parent, false);

		viewHolder = new ViewHolder();
		if (itemArray != null)
		{
			viewHolder.textView = (TextView) view.findViewById(R.id.item_get_info);
			viewHolder.textView.setText("找到了"+itemArray.get(position).level+"级的"+itemArray.get(position).itemname+",价值"+itemArray.get(position).value+"亨特");
		}
		view.setTag(viewHolder);
		return view;
	}

	static class ViewHolder
	{
		TextView textView;
	}
}